﻿using pcDAL;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web.Mvc;

namespace pcCore
{
    public static class Common
    {
        public static int GetRandomNumber()
        {
            int nexRanNum, count = 0;
            Random random = new Random(100000);
            nexRanNum =   random.Next(999999);
            CommonDAL dc = new CommonDAL();
            while (dc.CheckIfRandomNumberExists(nexRanNum))
            {
                count++;
                nexRanNum = random.Next(999999);
                if (count > 3)
                    break;
            }
            return nexRanNum;
        }

        public static List<SelectListItem> GetUserTypes(bool adminCall = false)
        {
            List<SelectListItem> userTypes = new List<SelectListItem>();
            userTypes.Add(new SelectListItem { Text = "Employee", Value = Convert.ToString((int)pcObjectLibrary.UserTypesEnum.Employee) });
            userTypes.Add(new SelectListItem { Text = "Manager", Value = Convert.ToString((int)pcObjectLibrary.UserTypesEnum.Manager) });
            if (adminCall)
            {
                userTypes.Add(new SelectListItem { Text = "Company Admin", Value = Convert.ToString((int)pcObjectLibrary.UserTypesEnum.CompanyAdmin) });
                userTypes.Add(new SelectListItem { Text = "Admin", Value = Convert.ToString((int)pcObjectLibrary.UserTypesEnum.Admin) });
            }
            userTypes.Add(new SelectListItem { Text = "Human Resources", Value = Convert.ToString((int)pcObjectLibrary.UserTypesEnum.HumanResources) });

            return userTypes;
        }

        public static List<SelectListItem> GetEmploymentTypes()
        {
            List<SelectListItem> employmentTypes = new List<SelectListItem>();
            employmentTypes.Add(new SelectListItem { Text = "FullTime", Value = Convert.ToString((int)pcObjectLibrary.EmploymentTypeEnum.FullTime) });
            employmentTypes.Add(new SelectListItem { Text = "Contract Hourly", Value = Convert.ToString((int)pcObjectLibrary.EmploymentTypeEnum.ContractHourly) });
            employmentTypes.Add(new SelectListItem { Text = "Contract Flat", Value = Convert.ToString((int)pcObjectLibrary.EmploymentTypeEnum.ContractFlat) });
            employmentTypes.Add(new SelectListItem { Text = "Part Time", Value = Convert.ToString((int)pcObjectLibrary.EmploymentTypeEnum.PartTime) });
            return employmentTypes;
        }

        public static List<SelectListItem> GetYearMonths(bool adminCall)
        {
            List<SelectListItem> yearMonths = new List<SelectListItem>();
            string[] months = DateTimeFormatInfo.CurrentInfo.MonthNames;
            int i = 1;
            foreach (var item in months)
            {
                yearMonths.Add(new SelectListItem
                {
                    Text = item + " - "+DateTime.Now.Year,
                    Value = i.ToString()
                });
                i++;
            }
            // DateTimeFormatInfo.CurrentInfo.GetMonthName(DateTime.Now.Month)
            yearMonths.Where(x => x.Value == DateTime.Now.Month.ToString()).First().Selected = true;
            return yearMonths;
        }
    }
}
